{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9493230b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing_extensions import TypedDict\n",
    "\n",
    "class State(TypedDict):\n",
    "    graph_state: str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b14e7997",
   "metadata": {},
   "outputs": [],
   "source": [
    "def node_1(state):\n",
    "    print(\"---Node 1---\")\n",
    "    return {\"graph_state\": state['graph_state'] +\"我很\"}\n",
    "\n",
    "def node_2(state):\n",
    "    print(\"---Node 2---\")\n",
    "    return {\"graph_state\": state['graph_state'] +\"高兴!\"}\n",
    "\n",
    "def node_3(state):\n",
    "    print(\"---Node 3---\")\n",
    "    return {\"graph_state\": state['graph_state'] +\"悲伤!\"}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70c2f027",
   "metadata": {},
   "source": [
    "## 边\n",
    "边连接点。\n",
    "如果您想要始终从例如：node_1 到node_2 ，则使用普通边 <br/> \n",
    "如果您想要可选在节点之间路由，则使用条件边。<br/>\n",
    "条件边被实现为基于某种逻辑返回下一个要访问的节点的函数。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a2f35e61",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "from typing import Literal\n",
    "\n",
    "def decide_mood(state) -> Literal[\"node_2\", \"node_3\"]:\n",
    "    \n",
    "    # 通常，我们会使用状态来决定下一个要访问的节点\n",
    "    user_input = state['graph_state'] \n",
    "    \n",
    "    # 在这里，我们在节点 2、3 之间进行 50/50 的分割\n",
    "    if random.random() < 0.5:\n",
    "\n",
    "        # 50% 的时间，我们返回节点 2\n",
    "        return \"node_2\"\n",
    "    \n",
    "    # 50% 的时间，我们返回节点 3\n",
    "    return \"node_3\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12e551c4",
   "metadata": {},
   "source": [
    "## 图构造\n",
    "现在，我们根据上面定义的组件构建图形。<br/>\n",
    "StateGraph类是我们可以用的图形类。<br/>\n",
    "首先，我们使用上面定义的State 类初始化StateGraph <br/>\n",
    "然后，我们添加节点和边。<br/>\n",
    "我们使用START 节点，一个特殊节点将用户输入发送到图形 ，以指示从哪里开始我们的图像。<br/>\n",
    "END 节点是一个代表终端节点的特殊节点。\n",
    "\n",
    "最后，我们编译我们的图表，对图表结构进行一基本检查。<br/>\n",
    "我们可以将图表可视化为美人鱼。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4a49ff3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOkAAAFNCAIAAABqr9/4AAAQAElEQVR4nOydB1wUR/vH5xrHFY6j9yKKgF3s3cSGihpREnvvJnZjjVH/vjGxR40ttsTuq7FiEkti775gxQYiSOco1zv/By+5lyQH4iuHu7Pz/dznPrszt3t3O7995plndma4xcXFiECgIVxEINATol0CXSHaJdAVol0CXSHaJdAVol0CXWG0dk3G4uxUrVphUiuMZmOxXkeDcCFfwObwWCInrtCJ4xXkiBgMi4HxXZ3W9OS24sUDVfpzjXeQo0DMETpxnT14eo0ZUR4HAbsgS69SGDlc1stH6mp1RCF1RKGRToh5ME6710/JUh6pfIIFUOqB4UJEZwx6M9yB8HdSH6tb9nCv1UyCmASDtPssQXFmd3aTzq7wQnihUZqunsjLS9d1HuLt4umAmAFTtHvtpEyrNrWN8YCqFmFKUZ7hxJaM5t3cajQQIwbACO1ePZnn4Mhu3BE3c2uTn3dm1mnpHFCT3u5QRWAj3PnlhyyeA4shwgW6DvO5f7no3qVChDuYa/f2mXxnd16Tzm6ISXQb4fM8QZmepEFYg7N2XyaqVHJTi+7MEq6FmM/875wp0KqMCF9w1u7Fn/Lqt3VGTCU0Unz5mAzhC7bafXi9yK+6QOrBlIDRP4loKsl6qS3I1iNMwVa7SXeVrXox0VsoTdveHvcuFyFMwVO7GUkag76YL+AgZgMdhxBzwDUMiqd2kx+ooJcfVS2zZs06ceIEens6duyYkZGB7AN0fUO/McIRPL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MFjk5xp9fLFXlOYrdaYW26dnpDvFYskg4bsOzoqVXfbR3jIvXp1nHCxWv7LY6yPSjMVIfUodk8a28F5uMmNn6eVLNNoD1cXoqjyFMb5IqYib4IXzAv1NotnIuyMO/Wt4lKpq7XCvNHljGfS69ltOuWOS/KGVy59ccpKWn3bWaZTUY2x/b1gW6FOhGVNvfebxd/KN2vURpHvlirs33vjR++wc83zGaWRq4zaXU1GpQX9MAA/MdaXouTvUop9ghxsZkrl+cZTbYnRNIbdA4827M3iEWuDg6V1gSESJlGaztYZjDoeGX8BomTB5drO4SSGp/5QV/XgJqYP4fEiHHCe5enuoV42iNYRkHk2UqBg67TAPwHuzOiERM72T/pejpiAOAtyDOLmCBcxBDt8hzYn0z3T7ubibBGrzHkJeUNmhOImAFTgkdu3vzoEZ5PLryE3iaEIxAUS4vPHDArADEGZs3ppFGa9nyd6hokxWxaJ1lqIduk6z0B52juP2HiPJDn9uUmP1R5Vndx9hYjmpOXUpj1tKBlT/fID5g1jh8xdv5deb7hwmFZRrLayV0o9hCJXR3ZHNq4T0aDSZGrVuWpzUZjcISwbYw7YiTMnTsavXYhkh8on95RKYqMqgKDg4Aj8RBolRQdJ8PjcxT5Or3G6O4vcHLhhkWKQLj2G9REfRit3dLodWa13AhqNpsQNYE+PqGEK5JwOVycR0NUHKJdAl1h3NqABGwg2iXQFaJdAl0h2iXQFaJdAl0h2iXQlf8HAAD//+V60doAAAAGSURBVAMAq9lAdAlBAfUAAAAASUVORK5CYII=",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.display import Image, display\n",
    "from langgraph.graph import StateGraph, START, END\n",
    "\n",
    "# 搭建图\n",
    "builder = StateGraph(State)\n",
    "builder.add_node(\"node_1\", node_1)\n",
    "builder.add_node(\"node_2\", node_2)\n",
    "builder.add_node(\"node_3\", node_3)\n",
    "\n",
    "# 添加边，逻辑\n",
    "builder.add_edge(START, \"node_1\")\n",
    "builder.add_conditional_edges(\"node_1\", decide_mood)\n",
    "builder.add_edge(\"node_2\", END)\n",
    "builder.add_edge(\"node_3\", END)\n",
    "\n",
    "# 添加\n",
    "graph = builder.compile()\n",
    "\n",
    "# View\n",
    "display(Image(graph.get_graph().draw_mermaid_png()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5232da91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---Node 1---\n",
      "---Node 3---\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'graph_state': '你好我很悲伤!'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph.invoke({\"graph_state\" : \"你好\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c8fcb3b5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10",
   "language": "python",
   "name": "python310"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
